<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台人员封停管理</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
</head>
<body>


<form class="layui-form">

    <div class="layui-form-item" style="margin-top: 15px">
        <label class="layui-form-label">用户账号：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" id="account" style="width: 400px">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">封停天数：</label>
        <div class="layui-input-inline">
            <select class="layui-select" name="days" lay-verify="required">
                <option value=""></option>
                <option value="3">3天</option>
                <option value="7">7天</option>
                <option value="30">30天</option>
                <option value="100">永久封禁</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">封停原因：</label>
        <div class="layui-input-inline">
            <textarea class="layui-textarea" name="reason" style="width: 400px"></textarea>
        </div>
    </div>

    <input type="hidden" name="endDate">



<div style="float: right; margin-bottom: 10px;margin-right: 10px;margin-top: 50px">
    <button type="button" lay-submit lay-filter="sub" class="layui-btn">确定</button>
    <button type="button" onclick="cancel()" class="layui-btn layui-btn-warm">取消</button>
</div>
</form>
</body>
<script>


    //获取当前时间
    var newTime;
    getTime();
    function getTime(){
        var myDate = new Date();
        var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
        var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
        var myToday = myDate.getDate(); //获取当前日(1-31)
        var myHour = myDate.getHours(); //获取当前小时数(0-23)
        var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
        var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
        newTime = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
    };

    //计算后的时间
    var getTimeEnd;
    function getTimeEnd(year,day){

        var myDate = new Date();
        var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
        myYear = myYear + year;

        var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
        var myToday = myDate.getDate(); //获取当前日(1-31)

        var myToday = myToday + day;
        if(myToday>30){
            myToday = myToday - 30;
            myMonth = myMonth + 1;
            if(myMonth > 12){
                myMonth = 1;
                myYear = myYear + 1;
            }
        }

        var myHour = myDate.getHours(); //获取当前小时数(0-23)
        var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
        var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
        getTimeEnd = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
    };


    layui.use(['layer','jquery','form'],function () {

        var $ = layui.$,
            layer = layui.layer,
            form = layui.form;

        //获取用户信息
        $('#account').val(parent.$('#account').val());
        var userId = parent.$('#userId').val();

        form.on('submit(sub)',function (obj) {
            var closure = obj.field;
            var days = parseInt(closure.days);

            if(days>= 100){
                getTimeEnd(days,0);
                $('input[name=endDate]').val(getTimeEnd);
                closure.days = 36500;
            }else{
                getTimeEnd(0,days);
                $('input[name=endDate]').val(getTimeEnd);
                closure.days = days;
            }

            closure.endDate = $('input[name=endDate]').val();
            closure.userId = userId;
            closure.type = 3;
            closure.remarks = '后台封禁';
            closure.startDate = newTime;

            //添加封禁记录
            $.ajax({
                 url: '/jurisdiction/shutDown'
                ,data: closure
                ,dataType: 'json'
                ,success:function(data){
                     if(data.data){

                         //关闭是否启用与状态
                         $.ajax({
                              url: '/jurisdiction/statusANDenabled'
                             ,data:{'userId': userId}
                             ,dataType: 'json'
                             ,success:function(data){
                                  if(data.data){
                                      var layer = parent.layer;
                                      layer.close(layer.index);
                                      parent.tableAjax();
                                      layer.msg('已封停账户');
                                  }
                             }
                         })


                     }
                }
            });

        });


    });

</script>
</html>